﻿using LiJu.Record;
using System;
using System.Drawing;
using System.Windows.Forms;

namespace LiJu
{
    public partial class TestRecords : Form
    {
        /// <summary>
        /// 左侧标签默认背景颜色
        /// </summary>
        public readonly Color defaultColor = Color.White;

        /// <summary>
        /// 左侧标签选中背景颜色，#0095ff
        /// </summary>
        public readonly Color selectColor = Color.FromArgb(0, 149, 255);

        /// <summary>
        /// 当前记录类型
        /// </summary>
        private RecordType CurrentRecordType = RecordType.Product;
        
        /// <summary>
        /// 产品记录控件
        /// </summary>
        ProductRecord ProductRecordControl = new ProductRecord();

        /// <summary>
        /// 任务记录控件
        /// </summary>
        TaskRecord TaskRecordControl = new TaskRecord();


        public TestRecords()
        {
            InitializeComponent();
            ProductRecordControl.Dock = DockStyle.Fill;
            TaskRecordControl.Dock = DockStyle.Fill;

            // 加载时启用默认双缓冲并提供无闪烁的图形呈现：
            this.DoubleBuffered = true;//设置本窗体
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
            SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲
        }

        /// <summary>
        /// 防止闪屏
        /// </summary>
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ExStyle |= 0x02000000;
                return cp;
            }
        }

        /// <summary>
        /// 加载刷新导航栏，重置记录数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TestRecords_Load(object sender, EventArgs e)
        {
            RefreshNavigate();
        }

        /// <summary>
        /// 刷新导航栏
        /// </summary>
        private void RefreshNavigate()
        {
            if (CurrentRecordType == RecordType.Product)
            {
                lbl_ProductRecord.BackColor = selectColor;
                lbl_Task.BackColor = defaultColor;
                lbl_ProductRecord.ForeColor = Color.White;
                lbl_Task.ForeColor = Color.Black;

                panel_RecordList.Controls.Clear();
                panel_RecordList.Controls.Add(ProductRecordControl);
            }
            else if (CurrentRecordType == RecordType.Task)
            {
                lbl_Task.BackColor = selectColor;
                lbl_ProductRecord.BackColor = defaultColor;
                lbl_Task.ForeColor = Color.White;
                lbl_ProductRecord.ForeColor = Color.Black;

                panel_RecordList.Controls.Clear();
                panel_RecordList.Controls.Add(TaskRecordControl);
            }
            ProductRecordControl.ResetProductAndBarcode();
            TaskRecordControl.ResetProductAndBarcode();
        }

        /// <summary>
        /// 切换产品测试记录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lbl_ProductRecord_Click(object sender, EventArgs e)
        {
            CurrentRecordType = RecordType.Product;
            RefreshNavigate();
        }

        /// <summary>
        /// 切换任务测试记录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lbl_Task_Click(object sender, EventArgs e)
        {
            CurrentRecordType = RecordType.Task;
            RefreshNavigate();
        }
    }
}
